<?php
declare (strict_types=1);

namespace app\common\library;

use Hprose\Http\Client;

class HproseClient
{
    public static $client = null;

    private function __construct()
    {
    }

    /*
     * @title 获取一个rpc客户端端
     * @param string $module 模块名称
     * @return object
     * */
    public static function ins(string $module): object
    {
        if (is_null(self::$client)) {
            self::$client = new Client(null, false);
            self::$client->setTimeout(5000); //5秒
        }
        $config = config('system.rpc_client');
        if (empty($config['ip'])) { //不指定ip
            self::$client->setUriList('http://' . $config['host'] . '/' . $module);
        } else {//指定ip
            self::$client->setUriList('http://' . $config['ip'] . '/' . $module);
            self::$client->setHeader('Host', $config['host']);
        }
        return self::$client;
    }

}